/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedbean;

import entity.Position;
import entity.Role;
import javax.faces.event.ActionEvent;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import session.stateless.PositionSessionBeanLocal;

/**
 *
 * @author Vincent
 */
@ManagedBean(name="positionDataTableBean")
@ViewScoped
public class PositionDataTableBean implements Serializable {
    @EJB 
    private PositionSessionBeanLocal positionSessionBeanLocal; 
    /** Creates a new instance of PositionDataTableBean */
    
    private Position selectedPosition;
    
    public PositionDataTableBean() {
    }
    
    public List<Position> getPositions() 
    { 
        return positionSessionBeanLocal.getPositions(); 
    }

    public List<Role> getRoles(Long positionId) 
    { 
        return positionSessionBeanLocal.getRoles(positionId); 
    }
        
    public Position getSelectedPosition() {
        return selectedPosition;
    }

    public void setSelectedPosition(Position selectedPosition) {
        this.selectedPosition = selectedPosition;
    }
    
    public void editPosition(ActionEvent event) throws IOException
    {
        Position selectedPosition = this.getSelectedPosition();
        if (selectedPosition != null){
            FacesContext.getCurrentInstance().getExternalContext().getFlash().put("selectedPosition", selectedPosition);
            FacesContext.getCurrentInstance().getExternalContext().redirect("editPosition.xhtml");       
        }
    }
    
    public void deleteSaleLead(ActionEvent event) throws IOException
    {
        Position selectedPosition = this.getSelectedPosition();
        if (selectedPosition != null){
            FacesContext.getCurrentInstance().getExternalContext().getFlash().put("selectedPosition", selectedPosition);
            FacesContext.getCurrentInstance().getExternalContext().redirect("deletePosition.xhtml");
        }
    }    
}
